import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';

import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn } from '#/adapter/vxe-table';
import type { DictApi, Sn } from '#/api';

import { reactive } from 'vue';

import { DictResp } from '#/api';

const status = reactive<DictApi.SelectOption[]>([]);

DictResp(['mes_order_status']).then((res) => {
  if (res.mes_order_status) {
    status.push(...res.mes_order_status);
  }
});
export const mes_order_status = status;

/**
 * 获取编辑表单的字段配置
 */
export function useSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'snId',
      dependencies: {
        triggerFields: ['snId'],
        show: false,
      },
    },
    {
      component: 'Input',
      fieldName: 'snCode',
      label: '物料编码',
      rules: 'required',
      formItemClass: 'col-span-6',
      componentProps: {
        placeholder: '请输入物料编码',
      },
    },

    {
      component: 'Input',
      fieldName: 'itemName',
      label: '物料名称',
      componentProps: {
        placeholder: '请输入物料名称',
      },
      formItemClass: ' col-span-6',
    },

    {
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入规格型号',
        maxLength: 50,
        rows: 3,
        showCount: false,
      },
      fieldName: 'specification',
      label: '规格型号',
      emptyStateValue: null,
      formItemClass: 'col-span-12',
    },

    {
      component: 'Input',
      fieldName: 'batchCode',
      label: '批次号',
      componentProps: {
        placeholder: '请输入批次号',
      },
      formItemClass: 'col-span-6',
    },

    {
      component: 'ElInputNumber',
      fieldName: 'batchCode',
      label: 'SN码数量',
      componentProps: {
        placeholder: '请输入需要生成的数量',
      },
      formItemClass: 'col-span-6',
    },
  ];
}
/**
 * 获取表格列配置
 * @param _onActionClick 表格操作按钮点击事件
 */
export function useColumns(
  _onActionClick?: OnActionClickFn<Sn.Row>,
): VxeTableGridOptions<Sn.Row>['columns'] {
  return [
    {
      field: 'checkbox',
      fixed: 'left',
      type: 'checkbox',
      width: 50,
    },
    {
      field: 'itemCode',
      fixed: 'left',
      title: '产品编码',
    },

    {
      field: 'itemName',
      title: '产品名称',
    },
    {
      field: 'specification',
      title: '规格型号',
    },
    {
      field: 'unitName',
      title: '单位',
    },
    {
      field: 'batchCode',
      title: '批次号',
    },
    {
      field: 'snNum',
      title: 'SN码数量',
    },
    {
      field: 'genDate',
      title: '生成时间',
    },
    {
      field: 'operation',
      title: '操作',
      width: 200,
      fixed: 'right',
      align: 'center',
      slots: { default: 'action' },
    },
  ];
}
